package com.pro.springbootshop.controller;

import com.pro.springbootshop.entity.AfterSales;
import com.pro.springbootshop.entityExtend.AfterSalesReturn;
import com.pro.springbootshop.service.AfterSalesService;
import com.pro.springbootshop.util.TokenUtil;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class AfterSalesController {
    @Autowired
    AfterSalesService afterSalesService;
    @ApiOperation("提交售后服务")
    @PostMapping("/api/afterSales/insert")
    public String saveAfterSales(@RequestBody AfterSales afterSales, HttpServletRequest request){
        String token = request.getHeader("token");
        return afterSalesService.saveAfterSales(afterSales,token);
    }
    @ApiOperation("商家获取售后服务")
    @GetMapping("/api/afterSales/{page}/{limit}")
    public AfterSalesReturn getAllAfterSales(@PathVariable(name = "page") Integer page, @PathVariable(name = "limit") Integer limit,HttpServletRequest request){
        String token = request.getHeader("token");
        return afterSalesService.getAllAfterSales(page,limit,token);
    }
    @ApiOperation("商家修改售后服务状态")
    @GetMapping("/api/afterSales/change/{afterSalesId}/{afterSalesState}")
    public String changeAfterSales(@PathVariable(name = "afterSalesId") Integer afterSalesId, @PathVariable(name = "afterSalesState") Integer afterSalesState){
        return afterSalesService.changeAfterSales(afterSalesId,afterSalesState);
    }
    @ApiOperation("买家获取售后记录")
    @GetMapping("/api/buyer/afterSales/{page}/{limit}")
    public AfterSalesReturn buyerGetAllAfterSales(@PathVariable(name = "page") Integer page, @PathVariable(name = "limit") Integer limit,HttpServletRequest request){
        String token = request.getHeader("token");
        return afterSalesService.buyerGetAllAfterSales(page,limit,token);
    }
}
